#pragma once

#include "Common.h"

template<int BYTS>
class PageMap
{
	typedef uintptr_t Number;

public:
	PageMap()
	{
		size_t size = sizeof(void*) << BYTS;
		size = Calculate::_minup(size, PAGESIZE);
		_array = (void**)SystemApply(size >> PAGESIZE);
		memset(_array, 0, sizeof(_array) << BYTS);
	}

	void Set(Number k, void* ptr)
	{
		assert(ptr);
		_array[k] = ptr;
	}

	void* Get(Number k)
	{
		if ((k >> BYTS) > 0) return nullptr;
		return _array[k];
	}

	void Delete(Number k)
	{
		_array[k] = nullptr;
	}
private:
	static const int _length = 1 << BYTS;
	void** _array;
};